home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Tools / Win95 Secrets / SETUP.Z / FSR32.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-19  |  1.8 KB  |  66 lines

  1. //==================================
  2. // FSR32 - Matt Pietrek 1995
  3. // FILE: FSR32.C
  4. //==================================
  5. #define WIN32_LEAN_AND_MEAN
  6. #include <windows.h>
  7. #include <stdio.h>
  8. #pragma hdrstop
  9.  
  10. typedef int (CALLBACK *GFSR_PROC)(int);
  11.  
  12. // Steal some #define's from the 16 bit WINDOWS.H
  13. #define GFSR_GDIRESOURCES      0x0001
  14. #define GFSR_USERRESOURCES     0x0002
  15.  
  16. // Prototype some undocumented KERNEL32 functions
  17. HINSTANCE WINAPI LoadLibrary16( PSTR );
  18. void WINAPI FreeLibrary16( HINSTANCE );
  19. FARPROC WINAPI GetProcAddress16( HINSTANCE, PSTR );
  20. void __cdecl QT_Thunk(void);
  21.  
  22. GFSR_PROC pfnFreeSystemResources = 0;   // We don't want these as locals in
  23. HINSTANCE hInstUser16;                  // main(), since QT_THUNK could
  24. WORD user_fsr, gdi_fsr;                 // trash them...
  25.  
  26. int main()
  27. {
  28.     char buffer[0x40];
  29.  
  30.     buffer[0] = 0;  // Make sure to use the local variable so that the
  31.                     // compiler sets up an EBP frame
  32.         
  33.     hInstUser16 = LoadLibrary16("USER.EXE");
  34.     if ( hInstUser16 < (HINSTANCE)32 )
  35.     {
  36.         printf( "LoadLibrary16() failed!\n" );
  37.         return 1;
  38.     }
  39.  
  40.     FreeLibrary16( hInstUser16 );   // Decrement the reference count
  41.  
  42.     pfnFreeSystemResources =
  43.         (GFSR_PROC) GetProcAddress16(hInstUser16, "GetFreeSystemResources");
  44.     if ( !pfnFreeSystemResources )
  45.     {
  46.         printf( "GetProcAddress16() failed!\n" );
  47.         return 1;
  48.     }
  49.     
  50.     __asm {
  51.         push    GFSR_USERRESOURCES
  52.         mov     edx, [pfnFreeSystemResources]
  53.         call    QT_Thunk
  54.         mov     [user_fsr], ax
  55.  
  56.         push    GFSR_GDIRESOURCES
  57.         mov     edx, [pfnFreeSystemResources]
  58.         call    QT_Thunk
  59.         mov     [gdi_fsr], ax
  60.     }
  61.  
  62.     printf( "USER FSR: %u%%  GDI FSR: %u%%\n", user_fsr, gdi_fsr );
  63.  
  64.     return 0;
  65. }
  66.